﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Axis.Dao.Product;
using Axis.BusinessObject.Product;

namespace Sotipha.Web.Views.Home
{
    public partial class ucRELATIVEPRODUCTS : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string Result = "";
            string ID = "-1";
            string PatternImage = "<li><a href=\"{0}\" style=\"float: left\">" +
                    "<img src=\"{1}\" width=\"45\" height=\"45px\" style=\"padding: 5px;margin-right: 10px; border: 1px solid #ccc\" /></a>"+
                    "<div style=\"display: block\">"+
                     "   <a href=\"{0}\">{2}</a>"+
                      "  <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"55%\" style=\"padding-top: 10px;margin-right: 0\">"+
                            "<tr>"+
                                "<td> {3}:"+                                   
                                "</td>"+
                                "<td align=\"right\">"+
                             "       <span>{4}</span>"+
                            "    </td>"+
                           " </tr>"+
                          "  <tr>"+
                         "       <td>"+
                        "        </td>"+
                       "         <td align=\"right\">"+
                      "              <del>{5}</del>"+
                     "           </td>"+
                    "        </tr>"+
                   "     </table>"+
                  "  </div>"+
                "</li>";
            CProductDao coreProduct = new CProductDao();
            if (Request.QueryString["ID"] != null)
                ID = Request.QueryString["ID"].ToString();
            IList<CProduct> listProduct = coreProduct.GetProductByCondition(string.Format("<InputValue Context=\"Relative\" ID=\"{0}\" />",ID));
            string Price = "Price";
            if (Session["lang"].ToString() == "vi")
            {
                ltrrelativeproducts.Text = "Sản phẩm liên quan";
                Price = "Giá";
            }
            if (listProduct != null)
                if (listProduct.Count > 0)
                {
                   foreach(CProduct item in listProduct )                    
                    {
                        var Link = BuildLink(item);
                        Result += string.Format(PatternImage, Link, item.Thumbnail, Session["lang"].ToString() == "vi" ? item.Name_VN : item.Name_EN, Price, String.Format("{0:0,0}", item.Price), String.Format("{0:0,0}", item.PriceOld));
                    }
                }

            ltrProduct.Text = Result;

        }
        public string BuildLink(CProduct Item)
        {
            string Result = "";
            switch (Item.ProductTypeID)
            {
                case 1:
                    Result = "../Towntalk/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 2:
                    Result = "../Lacquerware/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 3:
                    Result = "../Gifts/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 4:
                    Result = "../Sale/ProductDetail.aspx?ID=" + Item.ID;
                    break;
            }
            return Result;
        }
    }
}